﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       Shpm.App.Commons.Utils.CommonAjaxUtils
 * 类型：       应用共通层ajax
 * 功能说明：   页面交互 Ajax 类方法。
 * 作者：       zx
 * 创建日期：   2007/11/02
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/

using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Common.Dao;
using Shpm.App.Common.Bean;
using Shpm.App.Commons.Db.Beans.Inp;
using Shpm.App.Input.Bean;
using Shpm.App.Master.Bean;
using Shpm.App.Search.Dao;
using Shpm.App.Search.Bean;
using System.Collections;
using Shpm.System;
using Shpm.System.Db;
using Shpm.App.Input.Dao;
using Shpm.App.Third.Bean;
using System.Data.OleDb;
using Shpm.App.Third.Dao;

namespace Shpm.App.Commons.Utils
{
    public class CommonAjaxUtils 
    {

        // Construct
        public CommonAjaxUtils() { }

        // 检索职员信息 返回职员姓名
        [Ajax.AjaxMethod()]
        public static string GetEmployeeNameById(string paramEmployeeId)
        {
            CommonSearchDao dao = new CommonSearchDao();
            PersonEmployeeBean beanEmp = new PersonEmployeeBean();
            beanEmp.EmployeeId = paramEmployeeId;
            beanEmp = dao.FindEmployee(beanEmp);
            return (beanEmp == null) ? string.Empty : beanEmp.EmployeeName;
        }

        // 检索职员信息 返回职员职位
        [Ajax.AjaxMethod()]
        public static string GetEmployeeJobNameById(string paramEmployeeId)
        {
            CommonSearchDao dao = new CommonSearchDao();
            PersonEmployeeBean beanEmp = new PersonEmployeeBean();
            beanEmp.EmployeeId = paramEmployeeId;
            beanEmp = dao.FindEmployee(beanEmp);
            return (beanEmp == null) ? string.Empty : beanEmp.JobName;
        }

        // 检索职员信息 返回职员职位
        [Ajax.AjaxMethod()]
        public static string GetEmployeeGroupNameById(string paramEmployeeId)
        {
            CommonSearchDao dao = new CommonSearchDao();
            PersonEmployeeBean beanEmp = new PersonEmployeeBean();
            beanEmp.EmployeeId = paramEmployeeId;
            beanEmp = dao.FindEmployee(beanEmp);
            return (beanEmp == null) ? string.Empty : beanEmp.DepartName;
        }

        // 检索人员信息 返回会员姓名
        [Ajax.AjaxMethod()]
        public static string GetMemberNameById(string paramMemberId)
        {
            CommonSearchDao dao = new CommonSearchDao();
            ComMemberBean beanMem = new ComMemberBean();
            beanMem.MemberNo = paramMemberId;
            beanMem = dao.FindMember(beanMem);
            return (beanMem == null) ? string.Empty : beanMem.NameC;
        }
        // 检索人员信息 返回教师姓名
        [Ajax.AjaxMethod()]
        public static string GetTeacherNameById(string paramMemberId)
        {
            try
            {
                // 数値解析
                long lvalue = long.Parse(paramMemberId);
            }
            catch
            {
                return string.Empty;
            }
            CommonSearchDao dao = new CommonSearchDao();
            TeacherBean beanMem = new TeacherBean();
            beanMem.TeacherId = Convert.ToInt32(paramMemberId);
            beanMem = dao.GetTeacher(beanMem);
            return (beanMem == null) ? string.Empty : beanMem.TeacherName;
        }

        [Ajax.AjaxMethod()]
        public static ComMemberBean GetMemberInfoById(string paramMemberId)
        {
            CommonSearchDao dao = new CommonSearchDao();
            ComMemberBean beanMem = new ComMemberBean();
            beanMem.MemberNo = paramMemberId;
            beanMem = dao.FindMember(beanMem);
            return  beanMem;
        }

        // 检索楼层信息 返回楼层
        [Ajax.AjaxMethod()]
        public static IList FindFloor(string buildNo)
        {
            // DropDownList drop = (DropDownList)obj;
            SalesInfoDao dao = new SalesInfoDao();
            SalesInfoBean salesInfoBean = new SalesInfoBean();
            salesInfoBean.BuildingNo = buildNo;
            IList list = dao.FindBuildFloor(salesInfoBean);
            //drop.DataSource = list;
            //drop.DataBind();
            return list;
        }

        [Ajax.AjaxMethod()]
        public static IList FindRoom(string buildNo, string floor)
        {
            // DropDownList drop = (DropDownList)obj;
            SalesInfoDao dao = new SalesInfoDao();
            SalesInfoBean salesInfoBean = new SalesInfoBean();
            salesInfoBean.BuildingNo = buildNo;
            salesInfoBean.Floor = floor;
            IList list = null;
            try
            {
                list = dao.FindBuildRoom(salesInfoBean);
            }
            catch (Exception e)
            {
                throw new DataAccessException(e);
            }
            //drop.DataSource = list;
            //drop.DataBind();
            return list;
        }

        // get personal message        
        [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
        public static IList GetEmpMessage()
        {
            SysUserManager manager = new SysUserManager(HttpContext.Current);

            string employeeId = manager.getSysUserBean().getEmployeeBean().EmployeeId;

            MessagesDao dao = new MessagesDao();
            MessageBean bean = new MessageBean();
            IList list = null;

            bean.TargetEmpId = employeeId;
            list = dao.ListUnReadMessage(bean);

            return list;
        }

        // get public notify message
        [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
        public static IList GetNotifyMessage()
        {
            SysUserManager manager = new SysUserManager(HttpContext.Current);

            string userId = manager.getSysUserBean().getMstSysUserBean().SysUserId;
            string employeeId = manager.getSysUserBean().getEmployeeBean().EmployeeId;

            NotifyMessageDao dao = new NotifyMessageDao();
            MessageBean bean = new MessageBean();
            IList list = null;

            bean.EmployeeId = employeeId;
            bean.UserId = userId;
            list = dao.ListNotifyMessage(bean);

            return list;
        }

        //根据部门返回职位信息
        [Ajax.AjaxMethod()]
        public static IList FindPositions(string departId)
        {
            PersonJobDao dao = new PersonJobDao();
            PersonJobBean bean = new PersonJobBean();
            IList list = null;

            bean.DepartId = departId;
            list = dao.ListResult(bean);

            return list;
        }

        // 取得某年、月的备忘录数据
        [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
        public static IList FindByMemoInfo(string date)
        {
            SysUserManager manager = new SysUserManager(HttpContext.Current);

            MemoInfoDao dao = new MemoInfoDao();
            MemoInfoBean paramBean = new MemoInfoBean();
            paramBean.MemoDate = DateUtils.convertToDate(date);
            paramBean.EmployeeId = manager.getSysUserBean().getEmployeeBean().EmployeeId;
            IList dataList = dao.FindByMemoInfo(paramBean);

            return dataList;
        }

        // 备忘录定时提醒处理
        [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
        public static void ProcessCallMemo()
        {
            SysUserManager manager = new SysUserManager(HttpContext.Current);

            string userId = manager.getSysUserBean().getMstSysUserBean().SysUserId;
            string employeeId = manager.getSysUserBean().getEmployeeBean().EmployeeId;

            // MemoInfoBean memoBean = new MemoInfoBean();
            // memoBean.EmployeeId = employeeId;
            // MemoInfoDao memoDao = new MemoInfoDao();
            // IList dataList = memoDao.FindCallByMemoInfo(memoBean);

            MessageBean messageBean = new MessageBean();
            messageBean.EmployeeId = employeeId;
            messageBean.UserId = userId;

            MessagesDao dao = new MessagesDao();
            dao.ProcessCallMemo(messageBean);
        }

        // 返回某个城市的天气情况
        [Ajax.AjaxMethod()]
        public static CityBean GetWeatherForecast()
        {
            //FileStream fs = new FileStream("C:/OwcImage/WeatherForecast.xml", FileMode.Open, FileAccess.Read);
            //StreamReader sr = new StreamReader(fs);
            //sr.Close();
            //fs.Close();

            DataSet ds = new DataSet();
            ds.ReadXml(Constants.WEATHER_FORECAST_PATH);

            CityBean cityBean = new CityBean();

            // 城市名称
            cityBean.Name = Convert.ToString(ds.Tables[0].Rows[1][0]);
            // 城市描述
            cityBean.Description = Convert.ToString(ds.Tables[0].Rows[22][0]);
            // 天气预报列表
            cityBean.Weathers = new ArrayList();

            // 第一天天气预报
            WeatherForecastBean wfBean = new WeatherForecastBean();
            wfBean.CollectDate = Convert.ToString(ds.Tables[0].Rows[4][0]);
            wfBean.ForecastDate = Convert.ToString(ds.Tables[0].Rows[6][0]).Split(new string[] { " " }, StringSplitOptions.None)[0];
            wfBean.MinTemperature = Convert.ToString(ds.Tables[0].Rows[5][0]).Split(new string[] { " / " }, StringSplitOptions.None)[1];
            wfBean.MaxTemperature = Convert.ToString(ds.Tables[0].Rows[5][0]).Split(new string[] { " / " }, StringSplitOptions.None)[0];
            wfBean.Weather = Convert.ToString(ds.Tables[0].Rows[6][0]).Split(new string[] { " " }, StringSplitOptions.None)[1];
            wfBean.Wind = Convert.ToString(ds.Tables[0].Rows[7][0]);
            wfBean.Sunshine = Convert.ToString(ds.Tables[0].Rows[10][0]);
            wfBean.Detail = Convert.ToString(ds.Tables[0].Rows[11][0]);
            wfBean.Image1 = Convert.ToString(ds.Tables[0].Rows[8][0]);
            wfBean.Image2 = Convert.ToString(ds.Tables[0].Rows[9][0]);
            cityBean.Weathers.Add(wfBean);

            wfBean = new WeatherForecastBean();
            wfBean.CollectDate = Convert.ToString(ds.Tables[0].Rows[4][0]);
            wfBean.ForecastDate = Convert.ToString(ds.Tables[0].Rows[13][0]).Split(new string[] { " " }, StringSplitOptions.None)[0];
            wfBean.MinTemperature = Convert.ToString(ds.Tables[0].Rows[12][0]).Split(new string[] { " / " }, StringSplitOptions.None)[1];
            wfBean.MaxTemperature = Convert.ToString(ds.Tables[0].Rows[12][0]).Split(new string[] { " / " }, StringSplitOptions.None)[0];
            wfBean.Weather = Convert.ToString(ds.Tables[0].Rows[13][0]).Split(new string[] { " " }, StringSplitOptions.None)[1];
            wfBean.Wind = Convert.ToString(ds.Tables[0].Rows[14][0]);
            wfBean.Sunshine = null;
            wfBean.Detail = null;
            wfBean.Image1 = Convert.ToString(ds.Tables[0].Rows[15][0]);
            wfBean.Image2 = Convert.ToString(ds.Tables[0].Rows[16][0]);
            cityBean.Weathers.Add(wfBean);

            wfBean = new WeatherForecastBean();
            wfBean.CollectDate = Convert.ToString(ds.Tables[0].Rows[4][0]);
            wfBean.ForecastDate = Convert.ToString(ds.Tables[0].Rows[18][0]).Split(new string[] { " " }, StringSplitOptions.None)[0];
            wfBean.MinTemperature = Convert.ToString(ds.Tables[0].Rows[17][0]).Split(new string[] { " / " }, StringSplitOptions.None)[1];
            wfBean.MaxTemperature = Convert.ToString(ds.Tables[0].Rows[17][0]).Split(new string[] { " / " }, StringSplitOptions.None)[0];
            wfBean.Weather = Convert.ToString(ds.Tables[0].Rows[18][0]).Split(new string[] { " " }, StringSplitOptions.None)[1];
            wfBean.Wind = Convert.ToString(ds.Tables[0].Rows[19][0]);
            wfBean.Sunshine = null;
            wfBean.Detail = null;
            wfBean.Image1 = Convert.ToString(ds.Tables[0].Rows[20][0]);
            wfBean.Image2 = Convert.ToString(ds.Tables[0].Rows[21][0]);
            cityBean.Weathers.Add(wfBean);

            return cityBean;
        }

        [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
        public static IList GetBusinessMessage()
        {
            SysUserManager manager = new SysUserManager(HttpContext.Current);

            MessageBean paramBean = new MessageBean();
            paramBean.EmployeeId = manager.getSysUserBean().getEmployeeBean().EmployeeId;

            MessagesDao dao = new MessagesDao();
            IList dataList = dao.FindByEmployeeId(paramBean);

            return dataList;
        }

        //// 根据位置返回地图信息 
        [Ajax.AjaxMethod()]
        public static MstCommunityMapBean GetCommunityMapByPos(int row, int col)
        {
            CommunityMonitorDao dao = new CommunityMonitorDao();
            MstCommunityMapBean bean = new MstCommunityMapBean();
            bean.Row = row;
            bean.Col = col;
            bean = dao.GetCommunityMapByPos(bean);
            return bean;
        }

        // 按ipaddress查询当前地图信息 
        [Ajax.AjaxMethod()]
        public static MstCommunityMapBean GetCommunityMapByIpAddress(string ipAddress, int channel)
        {
            CommunityMonitorDao dao = new CommunityMonitorDao();
            MstCommunityMapBean bean = new MstCommunityMapBean();
            bean = dao.GetCommunityMapByAddress(ipAddress, channel);
            return bean;
        }

        // 按row, col查找当前区域地图上的摄像头 
        [Ajax.AjaxMethod()]
        public static IList FindByCctvOfMap(int row, int col)
        {
            CommunityMonitorDao dao = new CommunityMonitorDao();
            IList list = dao.listCCTV(row, col);
            return list;
        }

        // 查找报警信息
        [Ajax.AjaxMethod()]
        public static IList FindAlarm()
        {
            IList list = new ArrayList();
            AlarmDao dao = new AlarmDao();

            list = dao.FindUserAlarmActive();

            return list;
        }

        //三表抄送


        [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
        public static EWellSunBean GetRoomTable(string id)
        {
            if (id.Trim().Length == 6)
            {
                EWellSunBean bean = new EWellSunBean();
                EWellSunDao dao = new EWellSunDao();
                bean.Id = Convert.ToInt32(id.Substring(0, 2));
                bean.RoomId = Convert.ToInt32(id.Substring(2));
                bean = dao.GetTable(bean);
                if (bean != null)
                {
                    return bean;
                }
                else
                    return null;
            }
            else
                return null;
        }

        // 查找报警信息
        [Ajax.AjaxMethod()]
        public static IList FindWireless()
        {
            IList list = new ArrayList();
            WirelessDao dao = new WirelessDao();

            list = dao.FindWireless(new WirelessBean());

            return list;
        }

        // 查找报警信息
        [Ajax.AjaxMethod()]
        public static IList FindWirelessHis()
        {
            IList list = new ArrayList();
            WirelessDao dao = new WirelessDao();

            list = dao.FindWirelessHis(new WirelessBean());

            return list;
        }
    }
}